package apache_commons_utils;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

import java.io.*;
import java.nio.charset.Charset;
import java.util.List;

/**
 * @author: hu.shengjin
 * @date: 2019/12/5
 * @description:
 */
public class IOTest {
    public static void main(String[] args) throws IOException {
        File file = new File("C:\\Users\\hu.shengjin\\IdeaProjects\\mytest\\src\\main\\resources\\iotest.txt");
        File destFile = new File("C:\\Users\\hu.shengjin\\IdeaProjects\\mytest\\src\\main\\resources\\iotest1.txt");
        InputStream is = new FileInputStream(file);
        OutputStream os = new FileOutputStream("C:\\Users\\hu.shengjin\\IdeaProjects\\mytest\\src\\main\\resources\\iotest1.txt");
        //拷贝流
//        IOUtils.copy(is, os);
        //从流中读取内容，转为list
//        List<String> strings = IOUtils.readLines(is, Charset.defaultCharset());
//        System.out.println(strings);
        //对File操作
        List<String> strings = FileUtils.readLines(file, "UTF-8");
        FileUtils.writeStringToFile(file, "111111", "UTF-8", true);
        //file拷贝
        FileUtils.copyFile(file, destFile);
        os.close();
        is.close();
    }
}
